import {Component, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core';
import {Subject} from "rxjs/Rx";
import {ParentService} from "@train/parent/parent.service";
import {ToolsService} from "@shared/service/tools/tools.service";
import {StudentTestScoreDetailVO} from "@interface/index";
import {ActivatedRoute, Params} from "@angular/router";
import {AuthService} from "@shared/service/auth/auth.service";

@Component({
  selector: 'seed-scores-details',
  templateUrl: './scores-details.component.html',
  styleUrls: ['./scores-details.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class ScoresDetailsComponent implements OnInit, OnDestroy {
  public ngUnsubscribe: Subject<void> = new Subject<void>();
  public scoreInfo: StudentTestScoreDetailVO = new StudentTestScoreDetailVO();
  public params: any = {
    studentId: 7,
    levelId: 1,
    testModeId: 1,
    testMethodId: 1,
    testDateTimestamp: '',
    testItemText: '',
    ageGroupText: '',
    testMethodName: ''
  };

  constructor(
    private tools: ToolsService,
    private parentService: ParentService,
    private route: ActivatedRoute,
    private authSer: AuthService
  ) {

    this.route.params
      .switchMap((params: Params) => {
        this.params.studentId = params['studentId'];
        this.params.levelId = params['levelId'];
        this.params.testModeId = params['testModeId'];
        this.params.testMethodId = params['testMethodId'];
        return this.route.queryParams;
      }).subscribe((params: Params) => {
      this.params.testDateTimestamp = params['testDate'];
      this.params.testItemText = params['testItemText'];
      this.params.ageGroupText = params['ageGroupText'];
      this.params.testMethodName = params['testMethodName'];
      this.getStudentScoreDetail();
    });
  }

  getStudentScoreDetail() {
    // const query = {
    //   "studentId": 28601,
    //   "levelId": 3,
    //   "testModeId": 5,
    //   "testMethodId": 9,
    //   "testDateTimestamp": 1523894400000
    // };
    this.parentService.getStudentScoreDetail(this.params).subscribe((res) => {
      if (res.result === '0' && res.data) {
        this.scoreInfo = res.data;
      }
    });
  }

  ngOnInit() {
  }

  ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }

}
